package com.paradox.aggregation.provider.test;

import cn.hutool.core.util.ByteUtil;
import com.google.common.collect.Lists;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Mmap {
    public static void main(String[] args) throws Exception {
        try(RandomAccessFile aFile = new RandomAccessFile("E:\\test.txt", "rw")){
            try(FileChannel inChannel = aFile.getChannel()) {
                MappedByteBuffer buffer=inChannel.map(FileChannel.MapMode.READ_WRITE,0,aFile.length());
                System.out.println(buffer.capacity());
                System.out.println(buffer.limit());
                System.out.println(buffer.position());
                buffer.position(4);
                buffer.put("777".getBytes(StandardCharsets.UTF_8));
                buffer.force();
            }
        }
    }
}
